package at.gv.bmwf.fons.model.ontology.sources;

import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.ontology.OntModelSpec;
import com.hp.hpl.jena.query.QueryExecutionFactory;
import com.hp.hpl.jena.query.QueryFactory;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.vocabulary.RDFS;

public class DbpediaSource extends AbstractDataSource {

	@Override
	public OntModel createABox() {
		String queryString = 
				"prefix geo: <http://www.w3.org/2003/01/geo/wgs84_pos#> " +
				"prefix dbpedia: <http://dbpedia.org/resource/> " +
				"prefix dbpedia-owl: <http://dbpedia.org/ontology/> " +
				"prefix rdfs: <" + RDFS.getURI() + "> " +
				
				"CONSTRUCT { ?uni ?p ?o. } WHERE { " + 
				" SERVICE <http://dbpedia.org/sparql/> {" +
					"?uni a dbpedia-owl:University." +
					"?uni dbpedia-owl:country dbpedia:Austria." +
					"?uni ?p ?o." +
				"}}";
		
		OntModel newModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
		
		try {
			QueryExecutionFactory.create(QueryFactory.create(queryString), newModel).execConstruct(newModel);
			
		} catch (Exception e) {
			System.err.println("DBPedia datasource could not be added!");
			
		}
		return newModel;		
	}

}
